//
//  HXGuessLikeVC.m
//  ZCooking
//
//  Created by 韩旭 on 16/8/29.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "HXGuessLikeVC.h"
#import "HX_Macro.h"
#import "HXGuessLikeTCell.h"
#import "HXGuessLikeModel.h"
#import "HXTagsModel.h"

@interface HXGuessLikeVC ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *guessLike;
@end

@implementation HXGuessLikeVC
- (NSMutableArray *)guessLike {
    if (!_guessLike) {
        _guessLike = [NSMutableArray array];
    }
    return _guessLike;
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:0];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        [_tableView registerNib:[UINib nibWithNibName:@"HXGuessLikeTCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HXGuessLikeTCell"];
    }
    return _tableView;
}
- (void)createGusessLike {
    NSString *url = @"http://api.izhangchu.com/";
    NSString *body = @"page=1&methodName=UserLikes&size=20&version=4.40&";
    NSDictionary *dicHeader = @{@"Content-Type":@"application/x-www-form-urlencoded; charset=utf-8"};
    [HXNetTool postNetWithUrl:url body:body BodyStyle:HXBodyString Header:dicHeader Response:HXJSON Success:^(id result) {
        NSDictionary *results = result;
        NSDictionary *dicData = results[@"data"];
        NSArray *arrData = dicData[@"data"];
        for (NSDictionary *dicAll in arrData) {
            HXGuessLikeModel *like = [HXGuessLikeModel ModelWithDic:dicAll];
            [self.guessLike addObject:like];
        }
        [_tableView reloadData];
    } Failure:^(NSError *error) {
    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.guessLike.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HXGuessLikeTCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HXGuessLikeTCell"];
    cell.tagModel = self.guessLike[indexPath.row];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"猜你喜欢";
    [self createGusessLike];
    [self tableView];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 240;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
